home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / cg.lha / cg / src / cg.sed < prev    next >
Text File  |  1992-11-24  |  25KB  |  785 lines

  1. (* Ich, Doktor Josef Grosch, Informatiker, 8.1.1988 *)
  2.  
  3. MODULE cg;
  4.  
  5. FROM System    IMPORT GetArgCount, GetArgument, System, Exit;
  6. FROM Memory    IMPORT MemoryUsed;
  7. FROM IO        IMPORT StdOutput, StdError, WriteOpen, WriteClose, CloseIO,
  8.             WriteI, WriteS, WriteNl,
  9.             tFile, ReadOpen, ReadClose, EndOfFile, ReadNl;
  10. FROM Strings    IMPORT tString, AssignEmpty, Assign, Append, Concatenate,
  11.             ReadL, WriteL, ArrayToString, StringToArray;
  12. FROM Idents    IMPORT tIdent, NoIdent, MakeIdent, GetString, WriteIdent;
  13. FROM Sets    IMPORT tSet, MakeSet, ReleaseSet, Include, Exclude, IsEmpty,
  14.             Extract, Complement, Union, IsElement;
  15. FROM Errors    IMPORT StoreMessages, WriteMessages;
  16. FROM Scanner    IMPORT ScanTabName, BeginFile, Attribute, CurArg, ArgCount;
  17. FROM Parser    IMPORT Parser, ParsTabName;
  18. FROM Tree    IMPORT NoTree, tTree, Trace, Options, TreeRoot, QueryTree, ErrorCount,
  19.             HeapUsed, ModuleName, f, BeginTree2, ForallClasses, SourceFile,
  20.             WI, TypeNames, itTree, iNoTree, iModule, iInteger, IdentifyClass,
  21.             ViewName;
  22. FROM Tree2    IMPORT PutTree2;
  23. FROM Semantics    IMPORT Semantics, TypeCount;
  24. FROM Order    IMPORT Order;
  25. FROM Dialog    IMPORT Dialog;
  26.  
  27. IMPORT GramMod, TreeMod1, EvalMod, EvalMod2, EvalMod3;
  28. IMPORT GramC, GramYacc, TreeC1, EvalC, EvalC2, EvalC3;
  29.  
  30. CONST
  31.    DefExtMc    = ".md"    ;    (* file extensions for Modula (mc)    *)
  32.    ImpExtMc    = ".mi"    ;
  33.    LisExtMc    = ".imp";
  34.  
  35.    DefExtC    = ".h"    ;    (* file extensions for C        *)
  36.    ImpExtC    = ".c"    ;
  37.  
  38. VAR
  39.    CgLib    ,
  40.    DefFile    ,
  41.    TreeFile    ,
  42.    EvalFile    ,
  43.    String    ,
  44.    PathS    : tString;
  45.    Argument    ,
  46.    PathA    : ARRAY [0..255] OF CHAR;
  47.    j        : SHORTCARD;
  48.    ch        : CHAR;
  49.    AllOptions    : tSet;
  50.    HasArgs    : BOOLEAN;
  51.  
  52. PROCEDURE GenerateMacros;
  53.    VAR TypeTabFile    : tFile;
  54.    VAR s        : tString;
  55.    VAR i        : tIdent;
  56.    VAR j        : INTEGER;
  57.    BEGIN
  58.    IF IsElement (ORD ('c'), Options) THEN
  59.       ArrayToString    ("TypeTab.c", String);    (* name of type table for C *)
  60.    ELSE
  61.       ArrayToString    ("TypeTab.m", String);    (* name of type table for Modula *)
  62.    END;
  63.       Assign        (PathS, CgLib);
  64.       Concatenate     (PathS, String);
  65.       Append        (PathS, 0C);
  66.       StringToArray    (PathS, PathA);
  67.       TypeTabFile := ReadOpen (PathA);
  68.  
  69.       ArrayToString    ("yy" , PathS);        (* name of macro file *)
  70.       GetString        (iModule, ModuleName);
  71.       Concatenate    (PathS, ModuleName);
  72.       ArrayToString    (".w", String);
  73.       Concatenate    (PathS, String);
  74.       Append        (PathS, 0C);
  75.       StringToArray    (PathS, PathA);
  76.       f := WriteOpen (PathA);
  77.  
  78.       WHILE NOT EndOfFile (TypeTabFile) DO
  79.      ReadL (TypeTabFile, s);
  80.      i := MakeIdent (s);
  81.      IF (i <= TypeCount) AND IsElement (i, TypeNames) THEN
  82.         Exclude (TypeNames, i);
  83.         !# ifndef begin! WI (i); !!
  84.         ReadL (TypeTabFile, s);
  85.         WriteL (f, s);
  86.         !# endif!
  87.         !# ifndef close! WI (i); !!
  88.         ReadL (TypeTabFile, s);
  89.         WriteL (f, s);
  90.         !# endif!
  91.         !# ifndef read! WI (i); !!
  92.         ReadL (TypeTabFile, s);
  93.         WriteL (f, s);
  94.         !# endif!
  95.         !# ifndef write! WI (i); !!
  96.         ReadL (TypeTabFile, s);
  97.         WriteL (f, s);
  98.         !# endif!
  99.         !# ifndef get! WI (i); !!
  100.         ReadL (TypeTabFile, s);
  101.         WriteL (f, s);
  102.         !# endif!
  103.         !# ifndef put! WI (i); !!
  104.         ReadL (TypeTabFile, s);
  105.         WriteL (f, s);
  106.         !# endif!
  107.         !# ifndef copy! WI (i); !!
  108.         ReadL (TypeTabFile, s);
  109.         WriteL (f, s);
  110.         !# endif!
  111.         !# ifndef equal! WI (i); !!
  112.         ReadL (TypeTabFile, s);
  113.         WriteL (f, s);
  114.         !# endif!
  115.      ELSE
  116.         FOR j := 1 TO 8 DO
  117.            ReadNl (TypeTabFile);
  118.         END;
  119.      END;
  120.       END;
  121.       ReadClose (TypeTabFile);
  122.  
  123.       IF itTree <= TypeCount THEN Exclude (TypeNames, itTree); END;
  124.       WHILE NOT IsEmpty (TypeNames) DO
  125.      i := Extract (TypeNames);
  126.    IF IsElement (ORD ('c'), Options) THEN
  127.      !# ifndef begin! WI (i); !!
  128.      !# define begin! WI (i); !(a)!
  129.      !# endif!
  130.      !# ifndef close! WI (i); !!
  131.      !# define close! WI (i); !(a)!
  132.      !# endif!
  133.      !# ifndef read! WI (i); !!
  134.      !# define read! WI (i); !(a)    yyReadHex ((unsigned char *) & a, sizeof (a));!
  135.      !# endif!
  136.      !# ifndef write! WI (i); !!
  137.      !# define write! WI (i); !(a)    yyWriteHex ((unsigned char *) & a, sizeof (a));!
  138.      !# endif!
  139.      !# ifndef get! WI (i); !!
  140.      !# define get! WI (i); !(a)    yyGet ((char *) & a, sizeof (a));!
  141.      !# endif!
  142.      !# ifndef put! WI (i); !!
  143.      !# define put! WI (i); !(a)    yyPut ((char *) & a, sizeof (a));!
  144.      !# endif!
  145.      !# ifndef copy! WI (i); !!
  146.      !# define copy! WI (i); !(a, b)!
  147.      !# endif!
  148.      !# ifndef equal! WI (i); !!
  149.      !# define equal! WI (i); !(a, b)    memcmp ((char *) & a, (char *) & b, sizeof (a)) == 0!
  150.      !# endif!
  151.    ELSE
  152.      !# ifndef begin! WI (i); !!
  153.      !# define begin! WI (i); !(a)!
  154.      !# endif!
  155.      !# ifndef close! WI (i); !!
  156.      !# define close! WI (i); !(a)!
  157.      !# endif!
  158.      !# ifndef read! WI (i); !!
  159.      !# define read! WI (i); !(a)    yyReadHex (a);!
  160.      !# endif!
  161.      !# ifndef write! WI (i); !!
  162.      !# define write! WI (i); !(a)    yyWriteHex (a);!
  163.      !# endif!
  164.      !# ifndef get! WI (i); !!
  165.      !# define get! WI (i); !(a)    yyGet (a);!
  166.      !# endif!
  167.      !# ifndef put! WI (i); !!
  168.      !# define put! WI (i); !(a)    yyPut (a);!
  169.      !# endif!
  170.      !# ifndef copy! WI (i); !!
  171.      !# define copy! WI (i); !(a, b)!
  172.      !# endif!
  173.      !# ifndef equal! WI (i); !!
  174.      !# define equal! WI (i); !(a, b)    yyIsEqual (a, b)!
  175.      !# endif!
  176.    END;
  177.       END;
  178.  
  179.    IF IsElement (ORD ('c'), Options) THEN
  180.       !# ifndef begin! WI (itTree); !!
  181.       !# define begin! WI (itTree); !(a)    a = ! WI (iNoTree); !;!
  182.       !# endif!
  183.       !# ifndef close! WI (itTree); !!
  184.       !# define close! WI (itTree); !(a)    yyChild = a; a = ! WI (iNoTree); !; yyRelease! WI (iModule); ! (yyChild);!
  185.       !# endif!
  186.       !# ifndef read! WI (itTree); !!
  187.       !# define read! WI (itTree); !(a)    yyRead! WI (iModule); ! (a);!
  188.       !# endif!
  189.       !# ifndef write! WI (itTree); !!
  190.       !# define write! WI (itTree); !(a)    yyWrite! WI (iModule); ! (a);!
  191.       !# endif!
  192.       !# ifndef get! WI (itTree); !!
  193.       !# define get! WI (itTree); !(a)    yyGet! WI (iModule); ! (a);!
  194.       !# endif!
  195.       !# ifndef put! WI (itTree); !!
  196.       !# define put! WI (itTree); !(a)    yyPut! WI (iModule); ! (a);!
  197.       !# endif!
  198.       !# ifndef copy! WI (itTree); !!
  199.       !# define copy! WI (itTree); !(a, b)    yyCopy! WI (iModule); ! (b, & a);!
  200.       !# endif!
  201.       !# ifndef equal! WI (itTree); !!
  202.       !# define equal! WI (itTree); !(a, b)    IsEqual! WI (iModule); ! (a, b)!
  203.       !# endif!
  204.    ELSE
  205.       !# ifndef begin! WI (itTree); !!
  206.       !# define begin! WI (itTree); !(a)    a := ! WI (iNoTree); !;!
  207.       !# endif!
  208.       !# ifndef close! WI (itTree); !!
  209.       !# define close! WI (itTree); !(a)    yyChild := a; a := ! WI (iNoTree); !; yyRelease! WI (iModule); ! (yyChild);!
  210.       !# endif!
  211.       !# ifndef read! WI (itTree); !!
  212.       !# define read! WI (itTree); !(a)    yyRead! WI (iModule); ! (a);!
  213.       !# endif!
  214.       !# ifndef write! WI (itTree); !!
  215.       !# define write! WI (itTree); !(a)    yyWrite! WI (iModule); ! (a);!
  216.       !# endif!
  217.       !# ifndef get! WI (itTree); !!
  218.       !# define get! WI (itTree); !(a)    yyGet! WI (iModule); ! (a);!
  219.       !# endif!
  220.       !# ifndef put! WI (itTree); !!
  221.       !# define put! WI (itTree); !(a)    yyPut! WI (iModule); ! (a);!
  222.       !# endif!
  223.       !# ifndef copy! WI (itTree); !!
  224.       !# define copy! WI (itTree); !(a, b)    yyCopy! WI (iModule); ! (b, SYSTEM.ADR (a));!
  225.       !# endif!
  226.       !# ifndef equal! WI (itTree); !!
  227.       !# define equal! WI (itTree); !(a, b)    IsEqual! WI (iModule); ! (a, b)!
  228.       !# endif!
  229.    END;
  230.       WriteClose (f);
  231.    END GenerateMacros;
  232.  
  233. PROCEDURE ReadTraceTab;
  234.    VAR TraceTabFile    : tFile;
  235.    VAR s        : tString;
  236.    VAR t        : tTree;
  237.    BEGIN
  238.       TraceTabFile := ReadOpen ("TraceTab");    (* name of trace table *)
  239.       IF TraceTabFile >= 0 THEN
  240.      WHILE NOT EndOfFile (TraceTabFile) DO
  241.         ReadL (TraceTabFile, s);
  242.         t := IdentifyClass (TreeRoot^.Ag.Classes, MakeIdent (s));
  243.         IF t # NoTree THEN
  244.            SetTrace (t);
  245.            ForallClasses (t^.Class.Extensions, SetTrace);
  246.         END;
  247.      END;
  248.      ReadClose (TraceTabFile);
  249.       END;
  250.    END ReadTraceTab;
  251.  
  252. PROCEDURE SetTrace (t: tTree);
  253.    BEGIN INCL (t^.Class.Properties, Trace); END SetTrace;
  254.  
  255. PROCEDURE SmartOpen (FileName: tString): tFile;
  256.    VAR PathS: tString;
  257.    BEGIN
  258.       IF IsElement (ORD ('7'), Options) THEN
  259.      ArrayToString    ("yy", PathS);
  260.      Concatenate    (PathS, FileName);
  261.      Append        (PathS, 0C);
  262.      StringToArray    (PathS, PathA);
  263.       ELSE
  264.      Append        (FileName, 0C);
  265.      StringToArray    (FileName, PathA);
  266.       END;
  267.       RETURN WriteOpen    (PathA);
  268.    END SmartOpen;
  269.  
  270. PROCEDURE SmartClose (FileName: tString; f: tFile);
  271.    VAR PathS: tString;
  272.    BEGIN
  273.       WriteClose    (f);
  274.       IF IsElement (ORD ('7'), Options) THEN
  275.      ArrayToString    ("gmdupd ", PathS);
  276.      Concatenate    (PathS, FileName);
  277.      ArrayToString    (" yy", String);
  278.      Concatenate    (PathS, String);
  279.      Concatenate    (PathS, FileName);
  280.      Append        (PathS, 0C);
  281.      StringToArray    (PathS, PathA);
  282.      j := System    (PathA);
  283.       END;
  284.    END SmartClose;
  285.  
  286. BEGIN
  287.    AssignEmpty (CgLib);
  288.    SourceFile [0] := 0C;
  289.    ArgCount := GetArgCount () - 1;
  290.    HasArgs := FALSE;
  291.  
  292.    CurArg := 0;
  293.    LOOP
  294.       INC (CurArg);
  295.       IF CurArg > ArgCount THEN EXIT; END;
  296.       GetArgument (CurArg, Argument);
  297.       IF Argument [0] = '-' THEN 
  298.      IF Argument [1] = 'l' THEN 
  299.         AssignEmpty (CgLib);
  300.         j := 2;
  301.         LOOP
  302.            ch := Argument [j];
  303.            IF ch = 0C THEN EXIT; END;
  304.            Append (CgLib, ch);
  305.            INC (j);
  306.         END;
  307.         Append (CgLib, '/');
  308.      ELSE
  309.         j := 0;
  310.         LOOP
  311.            INC (j);
  312.            ch := Argument [j];
  313.            IF ch = 0C THEN
  314.           EXIT;
  315.            ELSIF ch = '?' THEN
  316.           Include (Options, ORD ('h'));
  317.           Include (Options, ORD ('H'));
  318.            ELSE
  319.           Include (Options, ORD (ch));
  320.            END;
  321.         END;
  322.         HasArgs := TRUE;
  323.      END;
  324.       ELSIF Argument [0] = '?' THEN 
  325.      Include (Options, ORD ('h'));
  326.      Include (Options, ORD ('H'));
  327.      HasArgs := TRUE;
  328.       ELSE
  329.      j := 0;
  330.      REPEAT
  331.             ch := Argument [j];
  332.         SourceFile [j] := ch;
  333.         INC (j);
  334.      UNTIL ch = 0C;
  335.      EXIT;
  336.       END;
  337.    END;
  338.  
  339.    IF NOT HasArgs THEN                (* {} -> {a, A}        *)
  340.       Include (Options, ORD ('a'));
  341.       Include (Options, ORD ('A'));
  342.    END;
  343.  
  344.    IF IsElement (ORD ('a'), Options) THEN    (* a -> {a-z, F, R, =} - {c, h, u, x, z} *)
  345.       MakeSet (AllOptions, 127);
  346.       FOR ch := 'a' TO 'z' DO
  347.      Include (AllOptions, ORD (ch));
  348.       END;
  349.       Include (AllOptions, ORD ('F'));
  350.       Include (AllOptions, ORD ('R'));
  351.       Include (AllOptions, ORD ('='));
  352.       Exclude (AllOptions, ORD ('c'));
  353.       Exclude (AllOptions, ORD ('h'));
  354.       Exclude (AllOptions, ORD ('u'));
  355.       Exclude (AllOptions, ORD ('x'));
  356.       Exclude (AllOptions, ORD ('z'));
  357.       Union (Options, AllOptions);
  358.       ReleaseSet (AllOptions);
  359.    END;
  360.  
  361.    IF IsElement (ORD ('k'), Options) OR        (* {k, q} -> o        *)
  362.       IsElement (ORD ('q'), Options) THEN
  363.       Include (Options, ORD ('o'));
  364.    END;
  365.  
  366.    IF IsElement (ORD ('w'), Options) OR        (* {w, p, f, k, t, b, y} -> , = Mark *)
  367.       IsElement (ORD ('p'), Options) OR
  368.       IsElement (ORD ('f'), Options) OR
  369.       IsElement (ORD ('k'), Options) OR
  370.       IsElement (ORD ('t'), Options) OR
  371.       IsElement (ORD ('b'), Options) OR
  372.       IsElement (ORD ('y'), Options) THEN
  373.       Include (Options, ORD (','));
  374.    END;
  375.  
  376.    IF IsElement (ORD ('w'), Options) OR        (* {w, r, p, g} -> ; = TreeStore *)
  377.       IsElement (ORD ('r'), Options) OR
  378.       IsElement (ORD ('p'), Options) OR
  379.       IsElement (ORD ('g'), Options) THEN
  380.       Include (Options, ORD (';'));
  381.    END;
  382.  
  383.    IF IsElement (ORD ('A'), Options) THEN    (* A -> {D, I}        *)
  384.       Include (Options, ORD ('D'));
  385.       Include (Options, ORD ('I'));
  386.    END;
  387.  
  388.    IF IsElement (ORD ('T'), Options) OR        (* {T, X, Y, Z} -> I    *)
  389.       IsElement (ORD ('X'), Options) OR
  390.       IsElement (ORD ('Y'), Options) OR
  391.       IsElement (ORD ('Z'), Options) THEN
  392.       Include (Options, ORD ('I'));
  393.    END;
  394.  
  395.    IF IsElement (ORD ('I'), Options) OR        (* {I, V, M, P, S, N, O, G, E, C, J, x, z, u} -> . = Order *)
  396.       IsElement (ORD ('V'), Options) OR
  397.       IsElement (ORD ('M'), Options) OR
  398.       IsElement (ORD ('P'), Options) OR
  399.       IsElement (ORD ('S'), Options) OR
  400.       IsElement (ORD ('N'), Options) OR
  401.       IsElement (ORD ('O'), Options) OR
  402.       IsElement (ORD ('G'), Options) OR
  403.       IsElement (ORD ('E'), Options) OR
  404.       IsElement (ORD ('C'), Options) OR
  405.       IsElement (ORD ('J'), Options) OR
  406.       IsElement (ORD ('x'), Options) OR
  407.       IsElement (ORD ('z'), Options) OR
  408.       IsElement (ORD ('u'), Options) THEN
  409.       Include (Options, ORD ('.'));
  410.    END;
  411.  
  412.    IF IsElement (ORD ('x'), Options) OR        (* {x, z, u} -> B    *)
  413.       IsElement (ORD ('z'), Options) OR
  414.       IsElement (ORD ('u'), Options) THEN
  415.       Include (Options, ORD ('B'));
  416.    END;
  417.  
  418.    IF IsElement (ORD ('T'), Options) THEN    (* T -> {X, Z}        *)
  419.       Include (Options, ORD ('X'));
  420.       Include (Options, ORD ('Z'));
  421.    END;
  422.  
  423.    IF IsElement (ORD ('X'), Options) THEN    (* X -> Y        *)
  424.       Include (Options, ORD ('Y'));
  425.    END;
  426.  
  427.    IF IsElement (ORD ('h'), Options) THEN
  428.       Exclude (Options, ORD ('h'));
  429.       f := StdOutput;
  430.       !!
  431.       !usage: cg [-options] [-ldir] [files]!
  432.       !!
  433.       !options for tree/graph module!
  434.       !!
  435.       ! a generate all except -ch (default)!
  436.       ! n generate node constructors    procedures n<node> (node)!
  437.       ! m generate node constructors    procedures m<node> (make)!
  438.       ! f generate node/graph destroyer procedure ReleaseTREE (free)!
  439.       ! F generate general    destroyer procedure ReleaseTREEModule (FREE)!
  440.       ! o generate ascii  node  writer  procedure WriteTREENode (output)!
  441.       ! r generate ascii  graph reader  procedure ReadTREE!
  442.       ! w generate ascii  graph writer  procedure WriteTREE!
  443.       ! g generate binary graph reader  procedure GetTREE!
  444.       ! p generate binary graph writer  procedure PutTREE!
  445.       ! R generate list reverser        procedure ReverseTREE!
  446.       ! t generate top down  traversal  procedure TraverseTREETD!
  447.       ! b generate bottom up traversal  procedure TraverseTREEBU!
  448.       ! y generate graph copy           procedure CopyTREE!
  449.       ! k generate graph checker        procedure CheckTREE!
  450.       ! q generate graph browser        procedure QueryTREE!
  451.       ! = generate tree equality test   procedure IsEqualTREE!
  452.       ! d generate definition     module!
  453.       ! i generate implementation module!
  454.       ! s generate import statements!
  455.       ! 4 generate tree/graph description in file TREE.TS!
  456.       ! 6 generate # line directives!
  457.       ! 7 touch output files only if necessary!
  458.       ! 8 report storage consumption!
  459.       ! c generate C code (default is Modula-2)!
  460.       ! h print help information for tree/graph module!
  461.       ! H print help information for evaluator  module!
  462.       ! -ldir specify the directory dir where cg finds its tables!
  463.       !!
  464.       !options for scanner and parser interface!
  465.       !!
  466.       ! x generate scanner specification!
  467.       ! z generate parser  specification for lalr!
  468.       ! u generate parser  specification for yacc!
  469.       ! v omit actions in the generated parser specifications!
  470.       ! j allow undefined node types; define implicitly as terminals!
  471.    (* ! e free! *)
  472.    END;
  473.  
  474.    IF IsElement (ORD ('H'), Options) THEN
  475.       Exclude (Options, ORD ('H'));
  476.       f := StdOutput;
  477.       !!
  478.       !usage: cg [-options] [-ldir] [files]!
  479.       !!
  480.       !options for evaluator module!
  481.       !!
  482.       ! A generate all, same as -DI (default)!
  483.       ! D generate definition     module!
  484.       ! I generate implementation module!
  485.       ! L generate a (lazy) evaluator for WAG (default OAG)!
  486.       ! W suppress warnings!
  487.       ! B allow missing attribute computations in extended node types!
  488.       ! V print visit sequences!
  489.       ! M print summary of all node types (rules) from source!
  490.       ! P print dependency relations DP!
  491.       ! S print dependency relations SNC!
  492.       ! N print dependency relations DNC!
  493.       ! O print dependency relations OAG!
  494.       ! G print attribute instances sorted by declaration order!
  495.       ! E print attribute instances sorted by evaluation order!
  496.       ! C print dependencies introduced for total order!
  497.       ! T generate evaluator with trace output (all actions, T = XZ)!
  498.       ! U trace only node types specified in file TraceTab!
  499.       ! X trace attribute evaluation actions with    values!
  500.       ! Y trace attribute evaluation actions without values!
  501.       ! Z trace visit actions!
  502.       ! J start dialog system!
  503.       ! Q browse internal data structure!
  504.       ! 0 optimize attribute storage!
  505.       ! 1 print inserted copy rules!
  506.       ! 2 print inherited attribute computation rules!
  507.       ! 3 print attribute storage assignment!
  508.       ! 5 generate code to check for cyclic dependencies!
  509.       ! 6 generate # line directives!
  510.       ! 7 touch output files only if necessary!
  511.       ! 8 report storage consumption!
  512.       ! 9 generate code to measure stack size!
  513.       ! c generate C code (default is Modula-2)!
  514.    (* ! . run order! *)
  515.    (* ! , generate procedure yyMark! *)
  516.    (* ! ; generate "TreeStore"! *)
  517.    (* ! / follow as early as possible strategy instead of as late as possible! *)
  518.       ! H print help information for evaluator  module!
  519.       ! h print help information for tree/graph module!
  520.       ! -ldir specify the directory dir where cg finds its tables!
  521.    (* ! K free! *)
  522.       !!
  523.       !implications!
  524.       !!
  525.       ! {}              -> {a, A}!
  526.       ! a               -> {a-z, F, R} - {c, e, h, u, x, z}!
  527.       ! A               -> {D, I}!
  528.       ! {L, T, X, Y, Z} -> I!
  529.       ! T               -> {X, Z}!
  530.    END;
  531.  
  532.    IF NOT IsEmpty (Options) THEN
  533.       ArrayToString    (ScanTabName, String);    (* name of scanner table *)
  534.       Assign        (PathS, CgLib);
  535.       Concatenate    (PathS, String);
  536.       Append        (PathS, 0C);
  537.       StringToArray    (PathS, ScanTabName);
  538.  
  539.       ArrayToString    (ParsTabName, String);    (* name of parser table *)
  540.       Assign        (PathS, CgLib);
  541.       Concatenate    (PathS, String);
  542.       Append        (PathS, 0C);
  543.       StringToArray    (PathS, ParsTabName);
  544.  
  545.    IF IsElement (ORD ('c'), Options) THEN
  546.       ArrayToString    ("int", String);
  547.    ELSE
  548.       ArrayToString    ("INTEGER", String);
  549.    END;
  550.       iInteger := MakeIdent (String);
  551.  
  552.       IF SourceFile [0] # 0C THEN
  553.      BeginFile (SourceFile);
  554.      ArrayToString (SourceFile, String);
  555.      Attribute.Position.File := MakeIdent (String);
  556.       END;
  557.       StoreMessages    (TRUE);
  558.       ErrorCount := Parser ();
  559.       BeginTree2;
  560.       Semantics        (TreeRoot);
  561.       IF ErrorCount > 0 THEN WriteMessages (StdError); CloseIO; Exit (1); END;
  562.    END;
  563.  
  564.    IF IsElement (ORD ('x'), Options) THEN
  565.       IF TreeRoot^.Ag.ScannerName = NoIdent THEN
  566.      ArrayToString    ("Scanner", PathS);
  567.       ELSE
  568.      GetString (TreeRoot^.Ag.ScannerName, PathS);
  569.       END;
  570.       ArrayToString    (".rpp", String);
  571.       Concatenate    (PathS, String);
  572.       f := SmartOpen    (PathS);
  573.    IF IsElement (ORD ('c'), Options) THEN
  574.       GramC.ScanSpec    (TreeRoot);
  575.    ELSE
  576.       GramMod.ScanSpec    (TreeRoot);
  577.    END;
  578.       SmartClose    (PathS, f);
  579.    END;
  580.  
  581.    IF IsElement (ORD ('z'), Options) THEN
  582.       GetString        (TreeRoot^.Ag.ParserName, ModuleName);
  583.       Assign        (PathS, ModuleName);
  584.       ArrayToString    (".lalr", String);
  585.       Concatenate    (PathS, String);
  586.       f := SmartOpen    (PathS);
  587.    IF IsElement (ORD ('c'), Options) THEN
  588.       GramC.ParsSpec    (TreeRoot);
  589.    ELSE
  590.       GramMod.ParsSpec    (TreeRoot);
  591.    END;
  592.       SmartClose    (PathS, f);
  593.    ELSIF IsElement (ORD ('u'), Options) THEN
  594.       GetString        (TreeRoot^.Ag.ParserName, ModuleName);
  595.       Assign        (PathS, ModuleName);
  596.       ArrayToString    (".y", String);
  597.       Concatenate    (PathS, String);
  598.       f := SmartOpen    (PathS);
  599.       GramYacc.ParsSpec    (TreeRoot);
  600.       SmartClose    (PathS, f);
  601.    END;
  602.  
  603.    IF IsElement (ORD ('.'), Options) THEN
  604.       Order        (TreeRoot);
  605.    END;
  606.  
  607.       WriteMessages    (StdError);
  608.       StoreMessages    (TRUE);
  609.  
  610.    IF IsElement (ORD ('Q'), Options) THEN
  611.       QueryTree        (TreeRoot);
  612.    END;
  613.  
  614.    IF IsElement (ORD ('J'), Options) THEN
  615.       Dialog        (TreeRoot);
  616.    END;
  617.  
  618.       IF ErrorCount > 0 THEN CloseIO; Exit (1); END;
  619.  
  620.    IF IsElement (ORD ('i'), Options) OR
  621.       IsElement (ORD ('X'), Options) THEN
  622.       GenerateMacros;
  623.    END;
  624.  
  625.    IF IsElement (ORD ('d'), Options) THEN
  626.       GetString        (iModule, ModuleName);
  627.       Assign        (PathS, ModuleName);
  628.    IF IsElement (ORD ('c'), Options) THEN
  629.       ArrayToString    (DefExtC , String);
  630.    ELSE
  631.       ArrayToString    (DefExtMc, String);
  632.    END;
  633.       Concatenate    (PathS, String);
  634.       Assign        (DefFile, PathS);
  635.       f := SmartOpen    (PathS);
  636.    IF IsElement (ORD ('c'), Options) THEN
  637.       TreeC1.TreeDefC    (TreeRoot);
  638.    ELSE
  639.       TreeMod1.TreeDefMod (TreeRoot);
  640.    END;
  641.       SmartClose    (PathS, f);
  642.  
  643.    IF NOT IsElement (ORD ('c'), Options) THEN
  644.       ArrayToString    ("gmdcpp ", PathS);        (* call cpp *)
  645.       Concatenate    (PathS, DefFile);
  646.       Append        (PathS, 0C);
  647.       StringToArray    (PathS, PathA);
  648.       j := System    (PathA);
  649.    END;
  650.    END;
  651.  
  652.    IF IsElement (ORD ('4'), Options) THEN
  653.       GetString        (ViewName, PathS);
  654.       ArrayToString    (".TS", String);
  655.       Concatenate    (PathS, String);
  656.       f := SmartOpen    (PathS);
  657.       WriteIdent    (f, iModule); WriteNl (f);
  658.       PutTree2        (f, TreeRoot^.Ag.Classes);
  659.       SmartClose    (PathS, f);
  660.    END;
  661.  
  662.    IF IsElement (ORD ('i'), Options) THEN
  663.       GetString        (iModule, ModuleName);
  664.       Assign        (PathS, ModuleName);
  665.    IF IsElement (ORD ('c'), Options) THEN
  666.       ArrayToString    (ImpExtC , String);
  667.    ELSE
  668.       ArrayToString    (ImpExtMc, String);
  669.    END;
  670.       Concatenate    (PathS, String);
  671.       Assign        (TreeFile, PathS);
  672.       f := SmartOpen    (PathS);
  673.    IF IsElement (ORD ('c'), Options) THEN
  674.       TreeC1.TreeImplC    (TreeRoot);
  675.    ELSE
  676.       TreeMod1.TreeImplMod (TreeRoot);
  677.    END;
  678.       SmartClose    (PathS, f);
  679.  
  680.    IF NOT IsElement (ORD ('c'), Options) THEN
  681.       ArrayToString    ("gmdcpp ", PathS);        (* call cpp *)
  682.       Concatenate    (PathS, TreeFile);
  683.       Append        (PathS, 0C);
  684.       StringToArray    (PathS, PathA);
  685.       j := System    (PathA);
  686.    END;
  687.    END;
  688.  
  689.    IF IsElement (ORD ('s'), Options) AND NOT IsElement (ORD ('c'), Options) THEN
  690.       GetString        (iModule, ModuleName);
  691.       Assign        (PathS, ModuleName);
  692.       ArrayToString    (LisExtMc, String);
  693.       Concatenate    (PathS, String);
  694.       f := SmartOpen    (PathS);
  695.       TreeMod1.ImportList (TreeRoot);
  696.       SmartClose    (PathS, f);
  697.    END;
  698.  
  699.    IF IsElement (ORD ('U'), Options) THEN
  700.       ReadTraceTab;
  701.    ELSIF NOT IsEmpty (Options) THEN
  702.       ForallClasses    (TreeRoot^.Ag.Classes, SetTrace);
  703.    END;
  704.  
  705.    IF IsElement (ORD ('D'), Options) THEN
  706.       GetString        (TreeRoot^.Ag.EvalName, ModuleName);
  707.       Assign        (PathS, ModuleName);
  708.    IF IsElement (ORD ('c'), Options) THEN
  709.       ArrayToString    (DefExtC , String);
  710.    ELSE
  711.       ArrayToString    (DefExtMc, String);
  712.    END;
  713.       Concatenate    (PathS, String);
  714.       f := SmartOpen    (PathS);
  715.    IF IsElement (ORD ('c'), Options) THEN
  716.       EvalC.EvalDefC    (TreeRoot);
  717.    ELSE
  718.       EvalMod.EvalDefMod (TreeRoot);
  719.    END;
  720.       SmartClose    (PathS, f);
  721.    END;
  722.  
  723.    IF IsElement (ORD ('I'), Options) THEN
  724.       GetString        (TreeRoot^.Ag.EvalName, ModuleName);
  725.       Assign        (PathS, ModuleName);
  726.    IF IsElement (ORD ('c'), Options) THEN
  727.       ArrayToString    (ImpExtC , String);
  728.    ELSE
  729.       ArrayToString    (ImpExtMc, String);
  730.    END;
  731.       Concatenate    (PathS, String);
  732.       Assign        (EvalFile, PathS);
  733.       f := SmartOpen    (PathS);
  734.    IF IsElement (ORD ('c'), Options) THEN
  735.       IF IsElement (ORD ('L'), Options) THEN
  736.      EvalC3.EvalImplC (TreeRoot);
  737.       ELSIF IsElement (ORD ('0'), Options) THEN
  738.      EvalC2.EvalImplC (TreeRoot);
  739.       ELSE
  740.      EvalC.EvalImplC (TreeRoot);
  741.       END;
  742.    ELSE
  743.       IF IsElement (ORD ('L'), Options) THEN
  744.      EvalMod3.EvalImplMod (TreeRoot);
  745.       ELSIF IsElement (ORD ('0'), Options) THEN
  746.      EvalMod2.EvalImplMod (TreeRoot);
  747.       ELSE
  748.      EvalMod.EvalImplMod (TreeRoot);
  749.       END;
  750.    END;
  751.       SmartClose    (PathS, f);
  752.  
  753.    IF NOT IsElement (ORD ('c'), Options) THEN
  754.       ArrayToString    ("gmdcpp ", PathS);        (* call cpp *)
  755.       Concatenate    (PathS, EvalFile);
  756.       Append        (PathS, 0C);
  757.       StringToArray    (PathS, PathA);
  758.       j := System    (PathA);
  759.    END;
  760.    END;
  761.  
  762.    IF NOT IsElement (ORD ('c'), Options) THEN
  763.       IF IsElement (ORD ('i'), Options) OR
  764.      IsElement (ORD ('X'), Options) THEN
  765.      ArrayToString    ("gmdrm yy" , PathS);        (* name of macro file *)
  766.      GetString    (iModule, ModuleName);
  767.      Concatenate    (PathS, ModuleName);
  768.      ArrayToString    (".w", String);
  769.      Concatenate    (PathS, String);
  770.      Append        (PathS, 0C);
  771.      StringToArray    (PathS, PathA);
  772.      j := System    (PathA);
  773.       END;
  774.    END;
  775.  
  776.    IF IsElement (ORD ('8'), Options) THEN
  777.       WriteNl (StdError);
  778.       WriteS  (StdError, "Memory"); WriteI (StdError, MemoryUsed, 8);
  779.       WriteS  (StdError, "  Heap"); WriteI (StdError, HeapUsed  , 8);
  780.       WriteNl (StdError);
  781.    END;
  782.    WriteMessages (StdError);
  783.    CloseIO; Exit (0);
  784. END cg.
  785.